/**
 * 
 */
package messenger;

import java.io.Serializable;

/**
 * @author (Group 42) William Orem, Joseph Hamilton, Kevin Benik
 * 
 */
public class Contact implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 4875490680661047099L;
	protected String userName;
	protected String pId;
	protected String firstName;
	protected String lastName;

	protected String phone;
	protected String eMail;
	protected int year;

	/**
	 * 
	 */
	public Contact() {
	}

	/**
	 * @param pId
	 * @param firstName
	 * @param lastName
	 * @param phone
	 * @param eMail
	 * @param year
	 */
	public Contact(String pId, String firstName, String lastName, String phone,
			String eMail, int year, String username) {
		this.pId = pId;
		this.firstName = firstName;
		this.lastName = lastName;
		this.phone = phone;
		this.eMail = eMail;
		this.year = year;
		this.userName = username;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof Contact))
			return false;
		Contact other = (Contact) obj;
		if (eMail == null) {
			if (other.eMail != null)
				return false;
		} else if (!eMail.equals(other.eMail))
			return false;
		if (firstName == null) {
			if (other.firstName != null)
				return false;
		} else if (!firstName.equals(other.firstName))
			return false;
		if (lastName == null) {
			if (other.lastName != null)
				return false;
		} else if (!lastName.equals(other.lastName))
			return false;
		if (pId == null) {
			if (other.pId != null)
				return false;
		} else if (!pId.equals(other.pId))
			return false;
		if (phone == null) {
			if (other.phone != null)
				return false;
		} else if (!phone.equals(other.phone))
			return false;
		if (userName == null) {
			if (other.userName != null)
				return false;
		} else if (!userName.equals(other.userName))
			return false;
		if (year != other.year)
			return false;
		return true;
	}

	/**
	 * @return the eMail
	 */
	public String geteMail() {
		return eMail;
	}

	/**
	 * @return the firstName
	 */
	public String getFirstName() {
		return firstName;
	}

	/**
	 * @return the lastName
	 */
	public String getLastName() {
		return lastName;
	}

	/**
	 * @return the phone
	 */
	public String getPhone() {
		return phone;
	}

	/**
	 * @return the pId
	 */
	public String getpId() {
		return pId;
	}

	/**
	 * @return the userName
	 */
	public String getUserName() {
		return userName;
	}

	/**
	 * @return the year
	 */
	public int getYear() {
		return year;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((eMail == null) ? 0 : eMail.hashCode());
		result = prime * result
				+ ((firstName == null) ? 0 : firstName.hashCode());
		result = prime * result
				+ ((lastName == null) ? 0 : lastName.hashCode());
		result = prime * result + ((pId == null) ? 0 : pId.hashCode());
		result = prime * result + ((phone == null) ? 0 : phone.hashCode());
		result = prime * result + year;
		return result;
	}

	/**
	 * @param eMail
	 *            the eMail to set
	 */
	public void seteMail(String eMail) {
		this.eMail = eMail;
	}

	/**
	 * @param firstName
	 *            the firstName to set
	 */
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	/**
	 * @param lastName
	 *            the lastName to set
	 */
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	/**
	 * @param phone
	 *            the phone to set
	 */
	public void setPhone(String phone) {
		this.phone = phone;
	}

	/**
	 * @param pId
	 *            the pId to set
	 */
	public void setpId(String pId) {
		this.pId = pId;
	}

	/**
	 * @param userName
	 *            the userName to set
	 */
	public void setUserName(String userName) {
		this.userName = userName;
	}

	/**
	 * @param year
	 *            the year to set
	 */
	public void setYear(int year) {
		this.year = year;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		if (userName != null) {
			builder.append("username: ");
			builder.append(userName);
			builder.append("   ");
		}
		if (pId != null) {
			builder.append("PID: ");
			builder.append(pId);
			builder.append("   ");
		}
		if (firstName != null) {
			builder.append("name: ");
			builder.append(firstName);
			builder.append(" ");
		}
		if (lastName != null) {
			builder.append(lastName);
			builder.append("   ");
		}
		if (phone != null) {
			builder.append("phone: ");
			builder.append(phone);
			builder.append("   ");
		}
		if (eMail != null) {
			builder.append("eMail: ");
			builder.append(eMail);
			builder.append("   ");
		}
		builder.append("graduation year: ");
		builder.append(year);
		return builder.toString();
	}

}
